// pages/examhome/examhome.js
const App = getApp();
const {
  get,
  post
} = App.require('request/index')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modifyList: [],
    catList: [{
      name: '训练模式',
      id: 1
    }],
    icon: 1,
    navHeight: App.globalData.navHeight,
    prolist: wx.getStorageSync('prolist') == '' ? wx.getStorageSync('prolist') : JSON.parse(wx.getStorageSync('prolist')),
    curr:1,
    length:10,
    Refresh: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getmodify();
  },
  check(e) {

    this.setData({
      icon: e.currentTarget.dataset.id
    })
  },
  getmodify() {
    let {prolist,curr,length,modifyList} = this.data
    post('/app/exam/member/book/list', {memberId:prolist.userid,curr:curr,length:length}).then(res => {
      
    
      if(res.data.records.length!=0){
        let list =   res.data.records
       list =  list.map(item=>{
          for (let i = 0; i < item.answerList.length; i++) {
            if(item.answerList[i].analysis){
              return {
                ...item,
                analysistr:item.answerList[i].analysis
              }
            }else{
              return {
                ...item
              }
            }
             
            
          }
        })
        console.log(list);
         
        this.setData({
          modifyList: modifyList.concat(list)
        })
      }

    })
  },
  detail(e) {
    let {
      prolist
    } = this.data;
    post('/app/exam/question/trainingMode', {
      repoId: e.currentTarget.dataset.id,
      memberId: prolist.userid
    }).then(res => {
      console.log(res);
      let str = JSON.stringify(res.data)
      wx.navigateTo({
        url: `/pages/examadmin/pages/traindetail/traindetail?data=${str}`
      })
    })


  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */  
  onPullDownRefresh() {
    this.setData({
      curr: 1,
      modifyList:[]
    })
    wx.showLoading({  
      title: '刷新中...',
    })
  
    wx.hideLoading();
    wx.stopPullDownRefresh()
    this.getmodify()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { 
    console.log('111111');  
    this.setData({
      curr: this.data.curr + 1
    })
    this.getmodify()

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },



  

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})